<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>
<%@ page language="java" import="com.limao.DBDataClass.CrowdVRHomeClass"%>
<%@ page language="java" import="com.limao.DBDataClass.CrowdUserAuthClass"%>
<%@ page language="java" import="com.limao.servlet.WebFunction"%>
<%
    String userid=CacheClass.isLogin(request,response);
    if (CacheClass.getIntValue(userid) == 0) {
        out.println("<script language='JavaScript'>alert('您还没有登陆！');location.href='mb/jsp/login.jsp';</script>"); //后退并刷新
        return;
    }
  CrowdUserAuthClass user= WebFunction.getUserInfo(request,response);
 if(user==null)
 {
	 out.println("<script language='JavaScript'>alert('用户不存在，或被平台禁用，请联系客服！');window.history.back(-1);</script>");
	 return;
 } 
 
CrowdVRHomeClass obj= WebFunction.getVrHomeInfo(request,response);
 if(obj==null)
 {
	 out.println("<script language='JavaScript'>alert('交易公司不存在，或平台已中止与供公司合作，暂不开放提单交易服务！');window.history.back(-1);</script>");
	 return;
 }
 
 int maxcashrmb=CacheClass.getIntValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("maxcashrmb").trim());
 
 %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>转入资金</title>
</head>
<body  ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc c3 f18">
        <span class="pa" style="left: 5px;" onclick="javascript:history.back();"><img src="mb/images/top_back.png" style="margin-top: 4px;height: 40px;width: 40px;"/></span>
        转入资金
    </div>
</div>

<div class="container jz" style="margin-top: 41px;">
    <section class="saveMoneyNotice w100 bcf of">
        <div class="clearfix of jz">
            <img src="mb/images/trumpet.png" class="db fl">
            <p class="fr c6 f12 mgl10 lh16">
                您为合作方[七彩云购]用户。转入资金将从您的七彩云购账户转至市场
                账户，以便投资。
            </p>
        </div>
    </section>
    <section class="saveMoneyBlock w100 of c3">
        <div class="saveMoneyDiv jz clearfix of" style="display:none">
            <label class="f14">资金类型</label>
            <input type="hidden" id="vrid" value="<%=obj.vrid%>"/>
            <input type="radio" name="moneyKind"  checked="checked" id="moneyKind1" value="1" style="margin-left: 6%;"/>
            <label for="moneyKind1" class="f16">抵押金</label>
            <%if(CacheClass.getIntValue(obj.iscommon)==1){ %>
            <input type="radio" name="moneyKind" id="moneyKind2" value="0" style="margin-left: 6%;"/>
            <label for="moneyKind2" class="f16">普通余额</label>
            <%} %>
        </div> 
        <div class="baitiaoLineMoney">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of">
            <label for="money" class="f14">转入金额</label>
            <input type="number" name="money" placeholder="" id="money" value="<%=user.principlelrmb%>" onblur="changermb();" onkeyup="value=this.value.replace(/\D+/g,'')"/><span class="f12 c6 mgl10">元</span>
        </div>
        <div class="baitiaoLineMoney">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of" style="display:none">
            <span class="fl f14 c3">余额</span>
            <p class="fr cff9933"><span style="font-size: 18px"><%=user.nowrmb %></span></p>
        </div>
        <div class="baitiaoLineMoney" style="display:none">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of">
            <span class="fl f14 c3">可用额度</span>
            <p class="fr cff9933"><span style="font-size: 18px"><%=user.principlelrmb%></span></p>
        </div>
        <div class="baitiaoLineMoney" style="display:none">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of" style="display:none">
            <span class="fl f14 c3">赠券类型</span>
            <%if(CacheClass.getIntValue(obj.type)==0){%>
            <p class="fr cff9933"><span class="f16">赠券不可亏损</span></p>
            <%}else{ %>
              <p class="fr cff9933"><span class="f16">赠券可亏损</span></p>
            <%} %>
        </div>
        <div class="baitiaoLineMoney">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of" style="display:none">
            <span class="fl f14 c3">目前赠券比例</span>
            <p class="fr cff9933" ><span style="font-size: 20px" id="marate"><%if(CacheClass.getIntValue(user.vrnum)==0){%><%=obj.marate%><%}else{%>0<%} %></span><span style="font-size: 19px" id="marate">%</span></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of" style="display:none">
            <span class="fl f14 c3">普通余额赠券比例</span>
            <p class="fr cff9933"><span style="font-size: 20px" id="commonrate"><%=obj.commonrate%></span><span style="font-size: 19px">%</span></p>
        </div>        
        <div class="baitiaoLineMoney">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of">
            <span class="fl f14 c3">赠券金额(最高<%=maxcashrmb%>)</span>
            <p class="fr cff9933" ><span style="font-size: 18px" id="payrmb">0</span></p>
        </div>
        <div class="baitiaoLineMoney">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of">
            <span class="fl f14 c3">申请后可用金额</span>
            <p class="fr cff9933" ><span style="font-size: 18px" id="addtotalrmb">0</span></p>
        </div>
        <div class="baitiaoLineMoney">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="w100" style="margin-top: 20px;margin-bottom: 30px;">
            <p class="w100 f12 c9 tc" style="margin: 0;color: #f51010;"">备注：赠券只有用户在第一次转入资金时才可获得；<Br>赠券只可用于市场交易，转出时赠券自动扣除。</p>
        </div>
       
    </section>

     <div class="w100 jz" style="margin-left:15px;margin-top: 20px;margin-bottom: 30px;width:90%;">
            <input id="agree" type="checkbox"  name="agree" value="agree" class="fl" style="margin-left:35px;"><a href="mb/jsp/riskWarning.jsp" class="w100 f14 c9 fl blue" style="width: 70%;margin-left:15px;">查阅《风险揭示书》并同意</lable>
     </div>



</div><!--container-->


<div class="detailBottm pf w100 of">
    <a onclick="Sub();" class="db w100 f18 cf f18 tc">确定转入</a>
</div>

<script>

    $(window).on("load", function() {
    
       
        $('input:radio[name="moneyKind"]').change(function () {
           changermb();
        })
    })
	var maxcashrmb='<%=maxcashrmb%>';
	
	var money='<%=user.principlelrmb%>';
 	$().ready(function() {
 	    if(money*1.0<0) money=0;
 		else
 			$('#money').val(money); 
 			
		changermb();
	});

    function changermb()
    {
    	var rmbtypeVal=$("input[name='moneyKind']:checked").val();
    	
    	console.log(rmbtypeVal);
    	
    	var money =$.trim($('#money').val());
    	if(money== ""){return;}
    	
    	
    	var money =$.trim($('#money').val());
    	
    	var rate=0;
    	if(rmbtypeVal==0)//普通
    	{
    		rate=$.trim($('#commonrate').html());
    	}
    	else
    	{
    		rate=$.trim($('#marate').html());
    	}
     	
    	var payrmbVal=rate*1.0*money/100.0;
    	if(payrmbVal>maxcashrmb*1.0)
    	{
    		payrmbVal=maxcashrmb*1.0;
    	}
    	
    	var addtotalrmbVal=1.0*payrmbVal+1.0*money;
    	
    	 $('#payrmb').html(''+payrmbVal);
    	 $('#addtotalrmb').html(''+addtotalrmbVal);
    	
    	
    	
    }

    function Sub() {
    
	    if ($('#agree').is(':checked') == false) {
	       showToast("请查阅《风险提示》并同意");
	    	return false;
	    }
    
    
        var money =$.trim($('#money').val());
        if(money== ""){
        	layer.alert('你还未填写金额');
            //$('#money').parent('.saveMoneyDiv').next('p').text('你还未填写金额');
            return false;
        } 
        else if(money*1.0== 0){
            layer.alert('金额不能为0');
            return false;
        }
        else
        {
            $('#money').parent('.saveMoneyDiv').next('p').text(' ');
        }
        
       var vridVal=$.trim($('#vrid').val());
       var rmbtypeVal=$("input[name='moneyKind']:checked").val();

       $.ajax({
            url: "PlugServlet",
            data: ''+JSON.stringify({m:243,rmb:money,vrid:vridVal,rmbtype:rmbtypeVal}),
            type: 'post',
            dataType: 'json',
            contentType:"application/json;charset=utf-8",
            beforeSend: function () {
            },
            success: function (data) {
              if(data['state']==1)
              {
                showToast(data.info);
                
                setTimeout(function(){
							history.back();
							},500);
              }
			  else
			  	layer.alert(data.info);
             },
            error: function (data) {
                showToast('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
        
    }
</script>


</body>
</html>
